<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/axios.min.js"></script>
</head>

<body>
    <input type="text" id="user">
    <input type="text" id="pwd">
    <input type="button" value="登录" id="btn">
    <script>
        /*
          接口地址：http://jx.xuzhixiang.top/ap/api/login.php
           接口请求方式：get
           接口参数：
            username用户名
            password密码
        */
        btn.onclick = function () {
            var username = user.value;
            var password = pwd.value;
            var loginAPI = "http://jx.xuzhixiang.top/ap/api/login.php";
            axios.get(loginAPI, { params: { username, password } }).then(r => {
                if (r.data.code == 0) {
                    alert(r.data.msg);
                } else {
                    alert(r.data.msg);
                    // 把id存入本地
                    localStorage.setItem("id",r.data.data.id);
                    // token登录的凭证，一般是登录的时候返回
                    localStorage.setItem("token", r.data.data.token);
                    location.href = "index.html";
                }
            })
        }
    </script>
</body>

</html>